package cn.com.cym.gamezao.web.recruit;

import cn.com.cym.gamezao.annotation.AuthToken;
import cn.com.cym.gamezao.base.BaseController;
import cn.com.cym.gamezao.base.BaseService;
import cn.com.cym.gamezao.entity.xmu.recruit.Certificate;
import cn.com.cym.gamezao.service.recruit.CertificateService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*;

@Api(tags = "r-证书管理")
@RestController
@RequestMapping(value = "cert")
@AuthToken(rule = "recruit.certificate")
@AllArgsConstructor
public class CertificateController extends BaseController<Certificate> {

    final CertificateService thisService;

    @Override
    public BaseService<Certificate> getService() {
        return thisService;
    }

    @ApiImplicitParam(name = "userId", value = "userId", required = true,dataType = "Long")
    @ApiOperation(value = "按id获取")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @GetMapping("/user/{userId}")
    @AuthToken(rule = "search")
    public ResponseEntity<?> getByUserId(@PathVariable @NonNull Long userId){
        Certificate t = this.thisService.getByUserId(userId);
        return ResponseEntity.ok(t);
    }

    @ApiOperation(value = "按id获取")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @GetMapping("/user")
    @AuthToken(rule = "search")
    public ResponseEntity<?> getOne(){
        Certificate t = this.thisService.getByUser();
        return ResponseEntity.ok(t);
    }


    @ApiImplicitParam(name = "userId", value = "userId", required = true,dataType = "Long")
    @ApiOperation(value = "按id获取")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @PostMapping("/user")
    @AuthToken(rule = "add")
    public ResponseEntity<?> save(@RequestBody @NonNull Certificate certificate){
        this.thisService.save(certificate);
        return ResponseEntity.ok(certificate);
    }
}
